import js from '@eslint/js';
import typescript from 'typescript-eslint';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
import prettier from 'eslint-plugin-prettier';
import prettierConfig from 'eslint-config-prettier';
import globals from 'globals';

export default typescript.config(
  // 基础配置
  js.configs.recommended,
  ...typescript.configs.recommended,
  
  // 主配置
  {
    files: ['**/*.{js,jsx,ts,tsx}'],
    
    plugins: {
      react,
      'react-hooks': reactHooks,
      prettier
    },
    
    languageOptions: {
      ecmaVersion: 2024,
      sourceType: 'module',
      globals: {
        ...globals.browser,
        ...globals.es2024,
        ...globals.node
      },
      parserOptions: {
        ecmaFeatures: {
          jsx: true
        }
      }
    },
    
    settings: {
      react: {
        version: 'detect'
      }
    },
    
    rules: {
      // TypeScript 规则
      '@typescript-eslint/no-explicit-any': 'warn',
      '@typescript-eslint/no-unused-vars': [
        'error',
        { 
          argsIgnorePattern: '^_',
          varsIgnorePattern: '^_',
          destructuredArrayIgnorePattern: '^_'
        }
      ],
      '@typescript-eslint/consistent-type-imports': [
        'error',
        { prefer: 'type-imports' }
      ],
      
      // React 规则
      'react/react-in-jsx-scope': 'off', // React 17+ 不需要
      'react/prop-types': 'off', // 使用 TypeScript
      'react/jsx-uses-react': 'off',
      'react/jsx-uses-vars': 'error',
      'react/jsx-no-target-blank': 'error',
      
      // React Hooks
      'react-hooks/rules-of-hooks': 'error',
      'react-hooks/exhaustive-deps': 'warn',
      
      // Prettier 集成
      'prettier/prettier': ['error', {}, { usePrettierrc: true }]
    }
  },
  
  // Prettier 配置覆盖 ESLint 格式规则
  prettierConfig,
  
  // 忽略文件
  {
    ignores: [
      '**/dist/**',
      '**/build/**',
      '**/node_modules/**',
      '**/.git/**',
      '**/coverage/**',
      '**/*.min.js',
      '**/vendor/**'
    ]
  }
);